﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication2.Model;

namespace WebApplication2.Controllers
{
    [ApiController]
    [Route("loginController")]
    public class LoginController: ControllerBase
    {
        [HttpGet("index")]
        public string Index()
        {
            return "loginController/index";
        }


        // http://localhost:5000/loginController/login/yejing/23232
        [HttpGet("login/{name}/{pwd}")]
        public string Login(string name,string pwd)
        {
            return $"{name}:{pwd}";
        }


        // http://localhost:5000/loginController/login2
        // Content-Type  :  application/json
        // {"name": "yejing","pwd": "13232"}
        [HttpPost("login2")]
        public string Login2([FromBody] User user)
        {
            Console.WriteLine(user.Name);
            Console.WriteLine(user.Pwd);
            return $"登录成功{user.Name}:{user.Pwd}";
        }


        // http://localhost:5000/loginController/login3
        // Content-Type: application/x-www-form-urlencoded
        // name:yeing  pwd:2323
        [HttpPost("login3")]
        public string Login3([FromForm] User user)
        {
            Console.WriteLine(user.Name);
            Console.WriteLine(user.Pwd);
            return $"登录成功{user.Name}:{user.Pwd}";
        }


        // http://localhost:5000/loginController/login4
        // 这里试过将User user作为参数但是没有绑定成功
        [HttpPost("login4")]
        public string Login4([FromHeader] string name, [FromHeader] string pwd)
        {
            Console.WriteLine(name);
            Console.WriteLine(pwd);
            return $"登录成功{name}:{pwd}";
        }


        // http://localhost:5000/loginController/login5/zhangsan/23243
        [HttpPost("login5/{name}/{pwd}")]
        public string Login5([FromRoute] string name, [FromRoute] string pwd)
        {
            Console.WriteLine(name);
            Console.WriteLine(pwd);
            return $"登录成功{name}:{pwd}";
        }


        [HttpPost("login6")]
        public string Login6([FromRoute] string name, [FromRoute] string pwd)
        {
            Console.WriteLine(name);
            Console.WriteLine(pwd);
            return $"登录成功{name}:{pwd}";
        }
    }
}
